/// @tags:
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long ll;

int const N = 100;

int n, m, q;
int A[N], B[N], cnt[N];

inline ll qpow(ll base, int exp) {
  ll res = 1;
  while (exp) {
    if (exp & 1) res = res * base;
    exp >>= 1;
    base = base * base;
  }
  return res;
}

inline int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= m; ++i) cin >> b[i];
  cin >> q;
  for (int a, b, c, d; q; --q) {
    cin >> a >> b >> c >> d;
    for (int j = a; j <= b; ++j) cnt[A[j]]++;
    int tot = 0;
    for (int j = c; j <= d; ++j) {
      if (cnt[B[j]]) {
        tot++, cnt[B[j]]--;
      }
    }
    
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("邮箱.in", "r", stdin);
  freopen("邮箱.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
